﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OffsetPath
{
    public sealed class ArcPatch
    {
        static Dictionary<PuntoDueD, AuxArc> _instance = null;
        static readonly object Padlock = new object();

        public static Dictionary<PuntoDueD, AuxArc> Instance
        {
            get
            {
                lock (Padlock)
                {
                    if (_instance == null) _instance = new Dictionary<PuntoDueD, AuxArc>();
                    {
                        return _instance;
                    }
                    return _instance;
                }
            }
        }

        public static void CreateNewModelClass()
        {
            lock (Padlock)
            {
                _instance = new Dictionary<PuntoDueD, AuxArc>();
            }
        }


        public static void AddPunto(PuntoDueD puntoDueD, AuxArc auxArc)
        {
            Instance.Add(puntoDueD, auxArc);
        }

        public static bool IsArcStart(PuntoDueD puntoDueD, out AuxArc auxArc)
        {
            foreach (var dueD in Instance.Keys)
            {
                if (Math.Round(dueD.X, 10) == Math.Round(puntoDueD.X, 10) &&
                    (Math.Round(dueD.Y, 10) == Math.Round(puntoDueD.Y, 10)))
                {

                    AuxArc value;
                    var rslt = Instance.TryGetValue(dueD, out value);
                    if (rslt)
                    {
                        auxArc = value;
                        return true;
                    }
                }

            }

            auxArc = null;
            return false;
        }

        internal static bool IsArcEnd(ForseLineaClassA pIni, ClassAtPuntoIncrementale incrementale, out AuxArc auxArc)
        {
            var endPoint = pIni.a;
            var incre = incrementale;

            var pnt = new PuntoDueD(endPoint.X + incre.a, endPoint.Y + incre.b);

            return IsArcStart(pnt, out auxArc);

        }

    }

    public class AuxArc
    {
        public double NormalAngle { get; set; }
        public double ArcRadius { get; set; }

        public PuntoDueD ArcCenter { get; set; }

        public bool ClockWise { get; set; }

        public double CurrentAngle { get; set; }

        public bool IsAngleStarting { get; set; }

        public PuntoDueD PreviousPoint { get; set; }

        public PuntoDueD EndPoint { get; set; }
    }
}
